<template>
    <div class="evaluationList">
        <div class="search-from flex justify-between">
            <el-form :inline="true" :model="searchFrom">
                <el-form-item label="报告名称：">
                    <el-input v-model="searchFrom.name" clearable placeholder="报告名称"></el-input>
                </el-form-item>
                <el-form-item label="诊改时间：">
                    <el-date-picker
                            v-model="searchFrom.createTime"
                            type="date"
                            placeholder="选择诊改时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="评价人：">
                    <el-input v-model="searchFrom.userName " clearable placeholder="评价人"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search">查询</el-button>
                    <slot name="handle"></slot>
                </el-form-item>
            </el-form>

            <div>
                <el-button type="primary" @click="myAssess">我的评价</el-button>
                <back-button></back-button>
            </div>
        </div>

        <el-table
                border
                :data="tableData"
                style="width: 100%">
            <el-table-column label="序号" width="50">
                <template slot-scope="scope">
                    <span>{{ searchFrom.pageSize * (searchFrom.pageIndex - 1)  + 1 + scope.$index }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="userName"
                    label="评价人">
            </el-table-column>
            <el-table-column
                    prop="createTime"
                    label="评价时间">
            </el-table-column>
            <el-table-column
                    prop="assessFraction"
                    label="评分（总分100）">
            </el-table-column>
            <el-table-column
                    prop="assessContent"
                    label="评价内容">
            </el-table-column>
        </el-table>

        <div class="margin-t-10 margin-b-10 text-center">
            <el-pagination
                    @current-change="changePage"
                    :current-page.sync="searchFrom.pageIndex"
                    :page-size="searchFrom.pageSize"
                    layout="prev, pager, next, jumper"
                    prev-text="上一页"
                    next-text="下一页"
                    :total="total">
            </el-pagination>
        </div>

        <!-- 添加评价-->
        <addAssess v-if="dialogParams.visible" :dialog-params="dialogParams" @getList="getList"></addAssess>
    </div>
</template>

<script>
    import { getAssessList } from '@/api/report';
    import { filterParams } from '@/config/utils';
    import addAssess from './addAssess'

    export default {
        name: 'evaluationList',
        components: {
            addAssess
        },
        data () {
            return {
                searchFrom: {
                    pageIndex: 1,
                    pageSize: 10,
                    reportId: '',
                    createTime: '',
                    name: '',
                    userName: ''
                },
                tableData: [],
                total: 0,
                // 添加评价
                dialogParams: {
                    visible: false,
                    id: ''
                }
            }
        },
        created () {
            this.searchFrom.reportId = this.$route.query.id;
            this.getList();
        },
        methods: {
            search () {
                this.searchFrom.pageIndex = 1;
                this.getList();
            },
            // 获取列表数据
            getList () {
                const params = filterParams(this.searchFrom);
                getAssessList(params).then(res => {
                    this.tableData = res.dataList || [];
                    this.total = res.total || 0;
                }).catch(() => {})
            },
            // 我的评价
            myAssess () {
                this.dialogParams.visible = true;
                this.dialogParams.id = this.searchFrom.reportId;
            },
            // 切换分页
            changePage (val) {
                this.searchFrom.pageIndex = val;
                this.getList();
            }
        }
    }
</script>

<style scoped>

</style>
